<!-- -----------------------------商品评论（表格） ------------------------------------>
<template>
  <el-table :data="tableData" border style="width: 100%">
    <el-table-column type="expand">
      <template #default="props">
        <div m="4">
          <p m="t-0 b-2"><span>商品编号</span> {{ props.row.id }}</p>
          <p m="t-0 b-2">
            <span>宣传画廊</span>
            <el-image
              v-for="(path, index) in props.row.gallery"
              :key="index"
              style="width: 40px; height: 40px"
              :src="path"
            ></el-image>
          </p>
          <p m="t-0 b-2"><span>商品介绍</span> {{ props.row.brief }}</p>
          <p m="t-0 b-2"><span>商品单位</span> {{ props.row.unit }}</p>
          <p m="t-0 b-2"><span>关键字</span> {{ props.row.zip }}</p>
          <p m="t-0 b-2"><span>类目ID</span> {{ props.row.categoryId }}</p>
          <p m="t-0 b-2"><span>品牌商ID</span> {{ props.row.brandId }}</p>
        </div>
      </template>
    </el-table-column>
    <el-table-column prop="goodsSn" align="center" label="商品ID" />
    <el-table-column prop="name" label="名称" align="center" />
    <el-table-column label="图片" align="center">
      <template #default="scope">
        <el-image
          style="width: 70px; height: 70px"
          :src="scope.row.picUrl"
        ></el-image>
      </template>
    </el-table-column>
    <el-table-column prop="" label="分享图" align="center"> </el-table-column>
    <el-table-column prop="" label="详情" align="center">
      <template #default="scope">
        <el-button
          type="primary"
          style="width: 56px; height: 28px"
          @click="openEvent(scope.row.detail)"
          >查看</el-button
        >
      </template>
    </el-table-column>

    <el-table-column prop="counterPrice" label="市场售价" align="center" />
    <el-table-column prop="retailPrice" label="当前价格" align="center" />
    <el-table-column prop="isNew" label="是否新品" align="center">
      <template #default="scope">
        <el-tag :type="scope.row.isNew ? 'success' : ''" disable-transitions>{{
          scope.row.isNew ? "新品" : "非新品"
        }}</el-tag>
      </template>
    </el-table-column>
    <el-table-column prop="isHot" label="是否热品" align="center">
      <template #default="scope">
        <el-tag :type="scope.row.isHot ? 'success' : ''" disable-transitions>{{
          scope.row.isNew ? "热品" : "非热品"
        }}</el-tag>
      </template>
    </el-table-column>
    <el-table-column prop="isOnSale" label="是否在售" align="center">
      <template #default="scope">
        <!-- {{ scope.row }}    拿到这个行的数据 -->
        <el-tag :type="scope.row.isOnSale ? 'success' : ''" disable-transitions
          >在售</el-tag
        >
      </template>
    </el-table-column>
    <el-table-column prop="keywords" label="操作" align="center" width="180">
      <template #default="scope">
        <!-- ----------------点击事件（编辑）---------------------- -->
        <el-button 
        type="primary" 
        style="width: 56px height: 28px"
        @click="compile(scope.row)"
          >编辑</el-button
        >
        <el-button type="danger" style="width: 56px; height: 28px"
          >删除</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>
  
  <script setup>
import { useStore } from "@/store/index.js";
import { onMounted, reactive, ref, watch, onUpdated, inject } from "vue";
import { shopList } from "@/api/api.js";
import { toReactive } from "@vueuse/shared";
import { ElMessageBox } from "element-plus";
import{useRoute,useRouter} from 'vue-router'
const router= useRouter()
const route= useRoute()
const store = useStore();
let tableData = reactive([]);
onMounted(() => {
  shopList(store.count).then((res) => {
    tableData.push(...res.data.data.list);
    store.total = res.data.data.total;
  });
});

// 监听 count 变化
store.$subscribe((a, state) => {
  //清空数组
  if (tableData) {
    tableData.splice(0, tableData.length);
  }
  shopList(state.count).then((res) => {
    tableData.push(...res.data.data.list);
  });
});

//查看    弹出框
const openEvent = inject("openEvent");

//编辑函数
function compile(params){
  // console.log(params,"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
  router.push({ name: 'compile',query:{id:params.id}})
}
</script>
  
  <style>
</style>